<?php
namespace app\admin\controller;
use think\Controller;
use think\Session;
class Index extends controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function login()
    {
    	$data = input('post.');

    	if (empty($data['name']) || empty($data['password'])) {

    		$this->error('请输入用户名或密码','admin/index/index');
    	}

        $name = $data['name'];

    	$stat = db('user')->where('name',$name)->select();
        if (!$stat) {
             return $this->error('用户不存在！');die;
        }
        $pwd = $stat[0]['password'];

        if (password_verify($data['password'], $pwd)) {

            $id = $stat[0]['id'];
            $agent_id = $stat[0]['agent_id'];

            Session::set('admin',$id);
            Session::set('agent_id',$agent_id);

            return $this->redirect('admin/ht/index');
        }else{
            return $this->error('请核对账号和密码');
        }


    }
}
